package com.ycw.controller.cjy;

import java.io.File;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.ycw.bean.BasicInfo;
import com.ycw.bean.ProDetaile;
import com.ycw.bean.ProInfo;
import com.ycw.bean.Projects;
import com.ycw.service.xiaocai.BasicinfoService;
import com.ycw.service.xiaocai.DetailDepictService;
import com.ycw.service.xiaocai.FileUploadService;
import com.ycw.service.xiaocai.InsertProjectsService;
import com.ycw.util.Msg;

@Controller
public class InsertProjectsController {

	@Autowired
	//合并到projects
	InsertProjectsService insertProjectsService;
	@Autowired
	//基本信息表的添加
    BasicinfoService basicinfoService;
	@Autowired
	//项目基本信息添加
	DetailDepictService detailDepictService;
	@Autowired
	// 实现项目图片上传  详细项目
	FileUploadService fileUploadService;
	
   //插入项目表中
	@RequestMapping(value="/insertProjects",method=RequestMethod.POST)
	@ResponseBody
	public Msg InsertProjects(HttpSession session) {
		System.out.println("1233542");
		/*boolean f=basicinfoService.insertBasic(basicInfo);
		if (f) {
			System.out.println("基本信息插入成功");
			return Msg.success();
		}
		//项目基本信息添加
		boolean f1=detailDepictService.insertDetail(proInfo);
		if (f1) {
			System.out.println("项目基本信息插入成功");
			return Msg.success();
		}
		//项目详细信息添加 包括文件上传
		System.out.println("文件上传");
		if (!file.isEmpty()) {//判断文件是否为空
			File files=new File("D:/downloads");
			if(!files.exists()){//如果文件夹不存在
				files.mkdir();//创建文件夹
			}
			String fileName = file.getOriginalFilename();//获取文件名字
			try {
				File file2 = new File(files+File.separator+fileName);
		            file.transferTo(file2);//把文件写入目标文件地址
		            proDetaile.setProdetaileVedio(file2.getAbsolutePath());
		            fileUploadService.UploadPhoto(proDetaile);
		
		        } catch (Exception e) {
		
		            e.printStackTrace();
		
		            return Msg.fail();
		
		        }
		
		}*/
		//basicInfo.setBasicinfoUsId(id);
		//proDetaile.setProdetaileUsId(id);
		//proInfo.setProinfoUsId(id);
		BasicInfo basicInfo=(BasicInfo)session.getAttribute("basicInfo");
		ProInfo proInfo=(ProInfo)session.getAttribute("proInfo");
		ProDetaile proDetaile=(ProDetaile)session.getAttribute("proDetaile");
		Projects projects=new Projects();
		projects.setPsUsId(basicInfo.getBasicinfoUsId());
		projects.setPsCustName(basicInfo.getBasicinfoCustName());
		projects.setPsCustPhone(basicInfo.getBasicinfoCustPhone());
		projects.setPsPstId(basicInfo.getBasicinfoPstId());
		projects.setPsCustAddress(basicInfo.getBasicinfoCustAddress());
		projects.setPsFile(proInfo.getProinfoFile());
		projects.setPsName(proInfo.getProinfoName());
		projects.setPsGoal(proInfo.getProinfoGoal());
		projects.setPsAddress(proInfo.getProinfoAddress());
		projects.setPsMoney(proInfo.getProinfoMoney());
		projects.setPsDays(proInfo.getProinfoDatenum());
		projects.setPsVideo(proDetaile.getProdetaileVedio());
		System.out.println("====="+projects.getPsVideo());
		projects.setPsStory(proDetaile.getProdetaileStory());
		projects.setPsSupport(proDetaile.getProdetaileSupport());
		projects.setPsRepay(proDetaile.getProdetaileRepay());
		projects.setPsAboutme(proDetaile.getProdetaileAboutme());
		insertProjectsService.insertProjects(projects);
		return Msg.success();
	}
}
